package com.putable.cgw.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.UIManager;

/**
 * 
 * Using this to test out the draw panel and game panel
 * 
 * Modularized the original BaseApplet
 * 
 * Draws a Blue Square Wherever you click
 * 
 * @author Evan
 * @author Todd
 *
 */
public class BaseApplet2 extends JApplet {

	
	private static final long serialVersionUID = 1L;
	
	private JMenu file;
	private JMenuBar mainMenuBar;
	private JPanel yardPanel;
	private JPanel infoPanel;
	private JSplitPane background;
	private JMenuItem jMenuItem2;
	private JMenuItem jMenuItem1;

	{
		try {
			UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("Look and feel failed");
		}
	}

	private Dimension windowSize = new Dimension(900, 550);
	
	public void init() {

		try {
				createGUI();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void createGUI(){
		// Set main layout
		BorderLayout thisLayout = new BorderLayout();
		getContentPane().setLayout(thisLayout);
		// Set size
		this.setSize(900, 550);
		this.setPreferredSize(new Dimension(900,550));
		createBackground();
		createInfoPanel();
		createYardPanel();
		createMenu();
		
	}
	
	public void createBackground(){
		// Background split pane, holds both panels
		background = new JSplitPane();
		getContentPane().add(background, BorderLayout.CENTER);
		background.setBorder(BorderFactory.createCompoundBorder(null, null));
		background.setBackground(new Color(106, 106, 106));
		background.setDividerLocation((int) (windowSize.width * 0.85));
		background.setDividerSize(5);
	}
	
	public void createInfoPanel(){
		infoPanel = new JPanel();
		background.add(infoPanel, JSplitPane.RIGHT);
		infoPanel.setPreferredSize(new Dimension((int) (windowSize.width * 0.25), windowSize.height));
		infoPanel.setBackground(new Color(192, 192, 192));
	}
	
	public void createYardPanel(){
		yardPanel = new YardPanel();
		yardPanel.setMinimumSize(new Dimension(20,20));
		background.add(yardPanel, JSplitPane.LEFT);
		yardPanel.setPreferredSize(new Dimension((int) (windowSize.width * 0.75), windowSize.height));
		yardPanel.setBackground(new Color(157, 0, 0));
	}
	
	public void createMenu(){
		// Main menu bar
		mainMenuBar = new JMenuBar();
		setJMenuBar(mainMenuBar);

		// Drop down menu
		file = new JMenu();
		mainMenuBar.add(file);
		file.setText("File");

		// items ect.
		jMenuItem1 = new JMenuItem();
		file.add(jMenuItem1);
		jMenuItem1.setText("An item");

		jMenuItem2 = new JMenuItem();
		file.add(jMenuItem2);
		jMenuItem2.setText("Anoter item");
	}
}
